import { http } from '../service';
import md5 from 'md5';

// 获取验证码
export const getVerifyCode = () => {
  return http.get('/uaa/token/verifyCode');
};

// 获取短信验证码
export const sendSmsCode = (params: any) => {
  return http.request({
    url: '/system/sms/sendSmsCode',
    method: 'GET',
    params,
  });
};
// 绑定微信
export function bindWxUser(data: any) {
  return http.middleware({
    url: `/system/Rest/wechat/bindUser`,
    method: 'POST',
    data,
  });
}

// 退出token
export function logoutToken() {
  return http.middleware({
    url: '/uaa/token/logout',
    method: 'POST',
  });
}

// 用户登录
export const login = (params: any) => {
  // 密码登录 否则是刷新token登录
  if (params && 'password' in params) {
    params.password = md5(params.password);
  }

  return http.middleware({
    url: '/uaa/oauth/token',
    method: 'POST',
    params,
  });
};

// 查询用户权限
export const userAuth = (userId: string | number) => {
  return http.middleware({
    url: '/system/Rest/user/userAuth',
    method: 'GET',
    params: { userId },
  });
};

//查询用户详情(平台)
export function getUserInfoById(params: any) {
  return http.middleware({
    url: `/system/Rest/user/getUserByUserId`,
    method: 'GET',
    params,
  });
}

// 修改当前用户的信息
export function updateCurrUser(data: any) {
  return http.middleware({
    url: `/system/Rest/user/updatePersonalInfo`,
    method: 'POST',
    data,
  });
}

//获取数据字典
export function getDictdata(data: any) {
  return http.middleware({
    url: `/system/Rest/dict/dictdata`,
    method: 'GET',
    params: data,
  });
}

//查询用户经理信息列表
export function getUserExperiencelist(params: any) {
  return http.middleware({
    url: `/system/Rest/user/getUserExperiencelist`,
    method: 'GET',
    params,
  });
}
//添加用户经历信息
export function saveUserExperience(data: any) {
  return http.middleware({
    url: `/system/Rest/user/saveUserExperience`,
    method: 'POST',
    data,
  });
}

//修改用户经历信息
export function updateUserExperience(data: any) {
  return http.middleware({
    url: `/system/Rest/user/updateUserExperience`,
    method: 'POST',
    data,
  });
}
//查询用户经历详情
export function getUserExperienceByExpId(params: any) {
  return http.middleware({
    url: `/system/Rest/user/getUserExperienceByExpId`,
    method: 'GET',
    params,
  });
}
// 设置签名密码
export function setSignPassword(data: any) {
  return http.middleware({
    url: `/system/Rest/user/updateSignPassword`,
    method: 'POST',
    data,
  });
}

// 设置签名密码
export function setPassword(data: any) {
  return http.middleware({
    url: `/system/Rest/user/updatePassword`,
    method: 'POST',
    data,
  });
}

// 查询策略
export function queryStrategy(params: any) {
  return http.middleware({
    url: `/system/Rest/password/strategy/queryByType`,
    method: 'GET',
    params,
  });
}

// 查询组织用户列表
export function getOrgUserList(params: any) {
  return http.middleware({
    url: '/system/Rest/user/getOrgUserList',
    method: 'GET',
    params,
  });
}

// 查询组织角色列表
export function getOrgRoleList(params: any) {
  return http.middleware({
    url: '/system/Rest/role/getOrgRoleList',
    method: 'GET',
    params,
  });
}
// 查询用户已加入的组织列表
export function joinList() {
  return http.middleware({
    url: `/system/Rest/userApply/getJoinList`,
    method: 'GET',
  });
}

// 更新用户头像
export function uploadProfilePhoto(data: any) {
  return http.request({
    url: `/system/Rest/user/uploadProfilePhoto`,
    method: 'POST',
    data,
  });
}
